<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义指令</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

</head>

<body>
    <div id="app">
        <p v-bg:aa.abc="'green'">自定义指令</p>
        <p>自定义指令</p>
        <p>自定义指令</p>

    </div>


    <script>
        // 全局注册 bg inserted的函数
        Vue.directive("bg", {
            inserted: function (el) {
                el.style.backgroundColor = "red";
            },
            bind: function (el) {
                el.style.color = "orange";

            }
        })

        var app = new Vue({
            el: "#app",
            // directives: {
            //     "fzc": {
            //         inserted: function (el) {
            //             el.style.color = "red"
            //         }
            //     },

            // }
            directives:{
                "bg":{
                    inserted(el,binding,vnode){
                        el.style.background=binding.value;
                        console.log(binding);
                        console.log(vnode);
                    }
                }
            }
        })

    </script>
</body>

</html>